package com.educate.book.web.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.educate.common.web.R;
import com.educate.book.model.bo.PictureBookBO;
import com.educate.book.rpc.api.PictureBookService;
import lombok.extern.log4j.Log4j2;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Log4j2
@RestController
@RequestMapping("pictureBook")
public class PictureBookController {

    @Reference(version = "${api.service.version}",
            application = "${dubbo.application.id}",
            url = "${dubbo.application.url}")
    private PictureBookService pictureBookService;

    @PostMapping(value = "/create")
    public R create(@RequestBody PictureBookBO bo) {
        pictureBookService.create(bo);
        return R.ok();
    }

    @PostMapping(value = "/delete")
    public R delete(@RequestBody PictureBookBO bo) {
        pictureBookService.delete(bo);
        return R.ok();
    }

    @PostMapping(value = "/delete/{pictureBookId}")
    public R delete(@PathVariable String pictureBookId) {
        pictureBookService.delete(pictureBookId);
        return R.ok();
    }

    @PostMapping(value = "/detail/{pictureBookId}")
    public R<PictureBookBO> detail(@PathVariable String pictureBookId) {
        PictureBookBO bo = pictureBookService.detail(pictureBookId);
        return R.ok(bo);
    }

    @PostMapping(value = "/detail")
    public R<PictureBookBO> detail(@RequestBody PictureBookBO bo) {
        PictureBookBO detail = pictureBookService.detail(bo);
        return R.ok(detail);
    }

    @PostMapping(value = "/update")
    public R<PictureBookBO> update(@RequestBody PictureBookBO bo) {
        pictureBookService.update(bo);
        return R.ok();
    }

    @PostMapping(value = "/query")
    public R<Page<PictureBookBO>> query(@RequestBody PictureBookBO bo) {
        Page<PictureBookBO> result = pictureBookService.query(bo, bo.pageable());
        return R.ok(result);
    }

    @PostMapping(value = "/list")
    public R<List<PictureBookBO>> list(@RequestBody PictureBookBO bo) {
        List<PictureBookBO> result = pictureBookService.list(bo);
        return R.ok(result);
    }

}
